package com.xiaoma.thread.interrupt;

/**
 停止一个线程
 *https://blog.csdn.net/zhuyong7/article/details/80852884
 * @author maj
 * @version 1.0.0
 */
public class InterruptThread1 extends Thread {

    public static void main(String[] args) {
        try {
            InterruptThread1 t = new InterruptThread1();
            t.start();
            Thread.sleep(200);
            t.interrupt();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void run() {
        super.run();
        for (int i = 0; i <= 200000; i++) {
            //判断是否被中断
            if (interrupted()) {
                System.out.println("被中断");
                //处理中断逻辑
                break;
            }
            System.out.println("i=" + i);
        }
    }
}
